package cn.maihe.elg.operation.supports.guarantee.serviceImpl;

import cn.maihe.elg.operation.exception.GuaranteeCheckRuntimeException;
import cn.maihe.elg.operation.service.guarantee.GuaranteeService;
import cn.maihe.elg.operation.supports.guarantee.GuaranteeServiceInterface;
import cn.maihe.elg.operation.supports.guarantee.dto.*;
import cn.maihe.elg.operation.supports.guarantee.enums.GuaranteeCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description
 * @Author caixh
 * @Date 2021/5/18.
 */
@Service
public class GuaranteeInnerServiceImpl implements GuaranteeServiceInterface {

    @Resource
    private GuaranteeService guaranteeService;

    /**
     * 保函验签通道枚举
     */
    @Override
    public GuaranteeCode guaranteeCodeEnum() {
        return GuaranteeCode.inner;
    }

    /**
     * 保函查验
     *
     * @param reqDTO
     * @return
     */
    @Override
    public BaseResponseDTO<GuaranteeInfoRespDTO> guaranteeInfo(GuaranteeInfoReqDTO reqDTO) {
        try {
            GuaranteeInfoRespDTO respDTO = guaranteeService.guaranteeCheck(reqDTO);
            return BaseResponseDTO.success(respDTO);
        }catch (GuaranteeCheckRuntimeException e){
            return BaseResponseDTO.exception(e.getMessage());
        }
    }

    @Override
    public BaseResponseDTO<FileCheckRespDTO> fileCheck(String md5, FileCheckResDTO reqDTO) {

        try {
            FileCheckRespDTO respDTO = guaranteeService.fileCheck(md5, reqDTO.getGuaranteeNo());
            return BaseResponseDTO.success(respDTO);
        }catch (GuaranteeCheckRuntimeException e){
            return BaseResponseDTO.exception(e.getMessage());
        }
    }
}
